package com.hs.wdss.dwr;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.hs.auth.model.HsAccount;
import com.hs.core.cache.DictCacheUtil;
import com.hs.core.db.DBMgr;
import com.hs.core.dwr.DwrHelper;
import com.hs.wdss.Constants;

public class DataProduceHelper   extends DwrHelper{

public String getSeqValue(String seqname){
	String sql = "select to_char(" + seqname + ".nextval) as seqvalue from dual";
	List datalist = this.getDbo().queryList(sql, null);
	Map data = (Map)datalist.get(0);
	return (String)data.get("seqvalue");
}

/**
 * 数据加工提交审核
 * @param id
 * @return
 */
public String submitAudit(String id){ 
	String sql = "update WDSS_DISINFO set STATE=2 where id =?";
	 this.getDbo().update(sql, new Object[]{id});
	
	return "";
}
/**
 * 添加医案来源信息
 * @return
 */	
public String addResource(String title,String maganame,String author,String keyword,String subjectword,String abstract_,String yearstr,
		String rollstr,String periodstr,String pagestr){
 	String rsid = getSeqValue("SEQ_WDSS_RESOURCE_ID");
 	HsAccount accinfo = this.getCurrentuser(this.getHttpServletRequest());
	String sql = "INSERT INTO WDSS_RESOURCE (ID, title, maganame, author, keyword, subjectword, abstract, yearstr,rollstr,periodstr" +
			",pagestr,dstype) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"; 
	this.getDbo().update(sql, new Object[]{rsid,title,maganame,author,keyword,subjectword,abstract_,yearstr,rollstr,periodstr,pagestr,"2"});
	return rsid;
}
/**
 * 更新医案来源信息
 */
public String updateResource(String rsid,String title,String maganame,String author,String keyword,String subjectword,String abstract_,String yearstr,
		String rollstr,String periodstr,String pagestr){
	String sql = "UPDATE WDSS_RESOURCE SET title=?, maganame=?, author=?, keyword=?, subjectword=?, abstract=?, yearstr=?," +
			"rollstr=?,periodstr=?, pagestr=? WHERE ID=? ";
	this.getDbo().update(sql, new Object[]{title,maganame,author,keyword,subjectword,abstract_,yearstr,rollstr,periodstr,pagestr,rsid});
	
	return rsid;
}
/**
 * 更新医案来源信息(书籍)
 * @return
 */	
public String updateResourceBook(String rsid,String bookname,String author,String publishunit,String keyword,String subjectword,String abstract_,String publishaddress,
		String publishdate,String banci,String yinci,String zishu,String isbnstr){
	String sql = "UPDATE WDSS_RESOURCE SET bookname=?, author=?, publishunit=?, keyword=?, subjectword=?, abstract=?, publishaddress=?," +
	"publishdate=?,banci=?, yinci=?,zishu=?,isbnstr=? WHERE ID=? ";
	this.getDbo().update(sql, new Object[]{bookname,author,publishunit,keyword,subjectword,abstract_,publishaddress,publishdate,
			banci,yinci,zishu,isbnstr,rsid});

	return rsid;
}
/**
 * 查询医案来源
 * @return
 */	
public String selectBook(String bookname){
	String sql = "select * from wdss_resource where id="+bookname; 
	List resultList = this.getDbo().queryList(sql, null);
	
	Map book = (Map)resultList.get(0);
	StringBuffer returnstr = new StringBuffer("{");
	returnstr.append("id:'").append(book.get("id")).append("',");
	returnstr.append("bookname:'").append(book.get("bookname")==null?"":book.get("bookname")).append("',");
	returnstr.append("author:'").append(book.get("author")==null?"":book.get("author")).append("',");
	returnstr.append("publishunit:'").append(book.get("publishunit")==null?"":book.get("publishunit")).append("',");
	returnstr.append("keyword:'").append(book.get("keyword")==null?"":book.get("keyword")).append("',");
	returnstr.append("subjectword:'").append(book.get("subjectword")==null?"":book.get("subjectword")).append("',");
	returnstr.append("abstract:'").append(book.get("abstract")==null?"":book.get("abstract")).append("',");
	returnstr.append("publishaddress:'").append(book.get("publishaddress")==null?"":book.get("publishaddress")).append("',");
	returnstr.append("publishdate:'").append(book.get("publishdate")==null?"":book.get("publishdate")).append("',");
	returnstr.append("isbnstr:'").append(book.get("isbnstr")==null?"":book.get("isbnstr")).append("',");
	returnstr.append("banci:'").append(book.get("banci")==null?"":book.get("banci")).append("',");
	returnstr.append("yinci:'").append(book.get("yinci")==null?"":book.get("yinci")).append("',");
	returnstr.append("zishu:'").append(book.get("zishu")==null?"":book.get("zishu")).append("'");
	returnstr.append("}"); 
	return returnstr.toString();
}
/**
 * 添加医案信息
 * @return
 */	
public String addDis(String discode,String maindesc,String dishis,String curedate,String content,String dsid,String disname,String chapter,String pagenum){
 	String disid = getSeqValue("SEQ_WDSS_DISINFO_ID");
 	HsAccount accinfo = this.getCurrentuser(this.getHttpServletRequest());
	String sql = "INSERT INTO WDSS_DISINFO (ID, discode, maindesc, dishis, curedate, content, dsid, disname,DATAPRODUCER,state,chapter,pagenum) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"; 
	this.getDbo().update(sql, new Object[]{disid,discode,maindesc,dishis,curedate,content,dsid,disname,accinfo.getId(),"1",chapter,pagenum});
	return disid;
}
/**
 * 更新医案信息
 */
public String updateDis(String disid,String discode,String maindesc,String dishis,String curedate,String content,
		String dsid,String disname,String chapter,String pagenum){
	String returnstr = "";
	System.out.println(":::" + disid);
	String sql = "UPDATE WDSS_DISINFO SET discode=?, maindesc=?, dishis=?, curedate=?, content=?, dsid=?, disname=?,chapter=?,pagenum=? WHERE ID=? ";
	returnstr = this.getDbo().update(sql, new Object[]{discode,maindesc,dishis,curedate,content,dsid,disname,chapter,pagenum,disid}) + "";
	
	return disid;
}
/**
 * 添加基本信息
 * @return
 */	
public String addUserinfo(String username,String userage,String useraddress,String agerangge,String memo,String sex,String disid){
 	String userid = getSeqValue("SEQ_WDSS_USERINFO_ID");
	String sql = "INSERT INTO WDSS_USERINFO (ID, username, userage, useraddress, agerangge, memo, sex, disid) VALUES (?,?,?,?,?,?,?,?)"; 
	this.getDbo().update(sql, new Object[]{userid,username,userage,useraddress,agerangge,memo,sex,disid});
	String sexstr = DictCacheUtil.getInst().getCodeNameByCode(sex, "24");
	String ageranggestr = DictCacheUtil.getInst().getCodeNameByCode(agerangge, "25");
	StringBuffer returnstr = new StringBuffer("[{");
	returnstr.append("id:'").append(userid).append("',");
	returnstr.append("username:'").append(username).append("',");
	returnstr.append("sex:'").append(sexstr).append("',");
	returnstr.append("userage:'").append(userage).append("',");
	returnstr.append("agerangge:'").append(ageranggestr).append("',");
	returnstr.append("useraddress:'").append(useraddress).append("',");
	returnstr.append("memo:'").append(memo).append("'");
	returnstr.append("}]"); 
	return userid +"$" + returnstr;
}
/**
 * 更新基本信息
 */
public String updateUserinfo(String userid,String username,String userage,String useraddress,String agerangge,String memo,String sex,String disid){
	String returnstr = "";
	System.out.println(":::" + userid);
	String sql = "UPDATE WDSS_USERINFO SET username=?, userage=?, useraddress=?, agerangge=?, memo=?, sex=?, disid=? WHERE ID=? ";
	returnstr = this.getDbo().update(sql, new Object[]{username,userage,useraddress,agerangge,memo,sex,disid,userid}) + "";
	
	return userid;
}
/**
 * 删除基本信息
 * @param pointid
 * @return
 */
public String delUserinfo(String userid){
	String returnstr = "";
	String sql = "delete from WDSS_USERINFO where id=?";
	returnstr = this.getDbo().update(sql, new Object[]{userid})+"";
	return userid;
}
/**
 * 添加并发病信息
 * @param paraname
 * @param memo
 * @param disid
 * @return
 */
public String addParaDis(String paraname,String memo,String disid){
	String paraid = getSeqValue("SEQ_WDSS_PARAINFO_ID");
	String sql = "insert into WDSS_PARAINFO(id,paraname,memo,DISID) VALUES(?,?,?,?)";
	this.getDbo().update(sql, new Object[]{paraid,paraname,memo,disid});
	StringBuffer returnstr = new StringBuffer("[{");
	returnstr.append("id:'").append(paraid).append("',");
	returnstr.append("paraname:'").append(paraname).append("',");
	returnstr.append("memo:'").append(memo).append("'");
	returnstr.append("}]"); 
	return paraid +"$" + returnstr;
}
/**
 * 删除疾病并发病信息
 * @param disid
 * @return
 */
public String delParaDis(String disparaid){
	String returnstr = "";
	String sql = "delete from  WDSS_PARAINFO where id=?";
	returnstr = this.getDbo().update(sql, new Object[]{disparaid})+"";
	
	return disparaid;
}
/**
 * 更新疾病并发症信息
 * @param paraid
 * @param paraname
 * @param memo
 * @return
 */
public String updateParaDis(String paraid,String paraname,String memo){
	String returnstr = "";
	String sql = "update WDSS_PARAINFO set paraname=?,memo=? where id=?";
	returnstr = this.getDbo().update(sql, new Object[]{paraname,memo,paraid})+"";
	return paraid;
}
/**
 * 添加病因信息
 * @param paraname
 * @param memo
 * @param disid
 * @return
 */
public String addDiscause(String datatype,String causecode,String memo,String disid){
	String discauseid = getSeqValue("SEQ_WDSS_DISCAUSEINFO_ID");
	String sql = "insert into WDSS_DISCAUSEINFO(id,datatype,causecode,memo,DISID) VALUES(?,?,?,?,?)";
	this.getDbo().update(sql, new Object[]{discauseid,datatype,causecode,memo,disid});
	String datatypestr = DictCacheUtil.getInst().getCodeNameByCode(datatype, "29");
	String ccode = "26";
	if("2".equals(datatype)){
		ccode = "27";
	}else if("3".equals(datatype)){
		ccode = "28";
	}
	String causecodestr = DictCacheUtil.getInst().getCodeNameByCode(causecode, ccode);
	StringBuffer returnstr = new StringBuffer("[{");
	returnstr.append("id:'").append(discauseid).append("',");
	returnstr.append("datatype:'").append(datatypestr).append("',");
	returnstr.append("causecode:'").append(causecodestr).append("',");
	returnstr.append("memo:'").append(memo).append("'");
	returnstr.append("}]"); 
	return discauseid +"$" + returnstr;
}
/**
 * 添加病因信息
 * @param paraname
 * @param memo
 * @param disid
 * @return
 */
public String addCause(String disid,String memo,String causecode26,String causecode27,String causecode28){
	String returnstr = "1";
    String delsql = "delete from WDSS_DISCAUSEINFO where disid=" + disid;
    this.getDbo().update(delsql, null);
	if(StringUtils.isNotBlank(causecode26)){
		String[] arr = causecode26.split(",");
		for(int j =0;j<arr.length;j++){
		    String str = arr[j];
		    String discauseid = getSeqValue("SEQ_WDSS_DISCAUSEINFO_ID");
		    String sql = "insert into WDSS_DISCAUSEINFO(id,datatype,causecode,memo,DISID) VALUES(?,?,?,?,?)";
	    	this.getDbo().update(sql, new Object[]{discauseid,"26",str,memo,disid});
		}
	}
	if(StringUtils.isNotBlank(causecode27)){
		String[] arr = causecode27.split(",");
		for(int j =0;j<arr.length;j++){
		    String str = arr[j];
		    String discauseid = getSeqValue("SEQ_WDSS_DISCAUSEINFO_ID");
		    String sql = "insert into WDSS_DISCAUSEINFO(id,datatype,causecode,memo,DISID) VALUES(?,?,?,?,?)";
	    	this.getDbo().update(sql, new Object[]{discauseid,"27",str,memo,disid});
		}
	}
	if(StringUtils.isNotBlank(causecode28)){
		String[] arr = causecode28.split(",");
		for(int j =0;j<arr.length;j++){
		    String str = arr[j];
		    String discauseid = getSeqValue("SEQ_WDSS_DISCAUSEINFO_ID");
		    String sql = "insert into WDSS_DISCAUSEINFO(id,datatype,causecode,memo,DISID) VALUES(?,?,?,?,?)";
	    	this.getDbo().update(sql, new Object[]{discauseid,"28",str,memo,disid});
		}
	}
	return returnstr;
}

/**
 * 更新病因信息
 * @param paraid
 * @param paraname
 * @param memo
 * @return
 */
public String updateDiscause(String discauseid,String datatype,String causecode,String memo){
	String returnstr = "";
	String sql = "update WDSS_DISCAUSEINFO set datatype=?,causecode=?,memo=? where id=?";
	returnstr = this.getDbo().update(sql, new Object[]{datatype,causecode,memo,discauseid})+"";
	return discauseid;
}
/**
 * 删除病因信息
 * @param pointid
 * @return
 */
public String delDiscause(String discauseid){
	String returnstr = "";
	String sql = "delete from WDSS_DISCAUSEINFO where id=?";
	returnstr = this.getDbo().update(sql, new Object[]{discauseid})+"";
	return discauseid;
}
/**
 * 添加症状信息
 * @param paraname
 * @param memo
 * @param disid
 * @return
 */
public String addPtom(String disid,String memo,String symcodestr){
	String returnstr = "1";
	String[] symstrList = symcodestr.split("#");
	System.out.println("" + symstrList.length);
	int symtypeNum = 30;
	for(int k=0; k<symstrList.length; k++){
		String symstr = symstrList[k];
		if(StringUtils.isNotBlank(symstr)){
			String[] arr = symstr.split(",");
			for(int j =0;j<arr.length;j++){
			    String str = arr[j];
			    String sql = "select id from WDSS_PTOMINFO where symtype="+ symtypeNum +" and symcode=" + str + " and disid=" + disid;
			    List resultList = this.getDbo().queryList(sql,null);
			    String pid = "";
			    for(int i=0; i<resultList.size(); i++){
			    	Map one = (Map)resultList.get(i);
			    	pid = one.get("id")+"";
			    }
			    if(!"".equals(pid)){
			    	sql = "update WDSS_PTOMINFO set symcode=? where symtype=?";
			    	this.getDbo().update(sql, new Object[]{str,pid});
			    }else{
			    	String ptomid = getSeqValue("SEQ_WDSS_PTOMINFO_ID");
			    	sql = "insert into WDSS_PTOMINFO(id,symtype,symcode,DISID) VALUES(?,?,?,?)";
			    	this.getDbo().update(sql, new Object[]{ptomid,symtypeNum,str,disid});
			    }
			}
		}
		symtypeNum ++;
	}
	
	return returnstr;
}
/**
 * 添加症状信息新
 * @param paraname
 * @param memo
 * @param disid
 * @return
 */
public String addPtomNew(String disid,String ptomname,String ptomvalue){
	String ptomtype = ptomname.substring(7,ptomname.length());
	String ptomid = getSeqValue("SEQ_WDSS_PTOMINFO_ID");
	String sql = "insert into WDSS_PTOMINFO(id,symtype,symcode,DISID) VALUES(?,?,?,?)";
	String returnstr = this.getDbo().update(sql, new Object[]{ptomid,ptomtype,ptomvalue,disid})+"";
	
	return ptomid;
}

/**
 * 删除症状信息
 * @param disid
 * @return
 */
public String delPtom(String ptomid){
	String returnstr = "";
	
	String sql = "delete from  WDSS_PTOMINFO where id=?";
	returnstr = this.getDbo().update(sql, new Object[]{ptomid})+"";
	return ptomid;
}
/**
 * 查询症状的所有证候信息
 * @param disid
 * @return
 */
public String querySymmcout(String ptoid){ 
	String sql = "select to_char(count(*)) as countall from WDSS_PTO_SYM where ptoid=?";
	List datalist = this.getDbo().queryList(sql, new Object[]{ptoid});
	Map data = (Map)datalist.get(0);
	String count = (String)data.get("countall");
	if("0".equals(count))
		return ptoid;
	return "";
}
/**
 * 查询症状的所有证候信息
 * @param disid
 * @return
 */
public String queryPtomNew(String disid,String ptomtype,String ptomvalue){ 
	ptomtype = ptomtype.substring(7,ptomtype.length());
	String sql = "select * from WDSS_PTOMINFO where disid=? and symtype=? and symcode=?";
	List datalist = this.getDbo().queryList(sql, new Object[]{disid,ptomtype,ptomvalue});
	String ptoid = "";
	if(datalist != null && datalist.size()>0){
		Map data = (Map)datalist.get(0);
		ptoid = String.valueOf(data.get("id"));
		sql = "select to_char(count(*)) as countall from WDSS_PTO_SYM where ptoid=?";
		List countlist = this.getDbo().queryList(sql, new Object[]{ptoid});
		Map countdata = (Map)countlist.get(0);
		String count = (String)countdata.get("countall");
		if("0".equals(count))
			return ptoid;
	}
	return  ptomtype + "$" + ptomvalue;
}
/**
 * 查询证候的所有治法信息
 * @param disid
 * @return
 */
public String queryCurecout(String symid){ 
	String sql = "select to_char(count(*)) as countall from WDSS_CUREMETHOD where symid=?";
	List datalist = this.getDbo().queryList(sql, new Object[]{symid});
	Map data = (Map)datalist.get(0);
	String count = (String)data.get("countall");
	/*String sql1 = "select to_char(count(*)) as countall from WDSS_PTO_SYM where symid=?";
	List datalist1 = this.getDbo().queryList(sql, new Object[]{symid});
	Map data1 = (Map)datalist1.get(0);
	String count1 = (String)data1.get("countall");*/
	if("0".equals(count) )
		return symid;
	return "";
}

/**
 * 删除证候信息
 * @param disid
 * @return
 */
public String delSym(String symid,String wdssid){
	String returnstr = "";
	
	String sql = "delete from  WDSS_SYMINFO where id=?";
	returnstr = this.getDbo().update(sql, new Object[]{symid})+"";
	sql = "delete from wdss_pto_sym where disid=? and symid=?";
	this.getDbo().update(sql, new Object[]{wdssid,symid});
	return symid;
}
/**
 * 查询治法的所有方剂信息
 * @param disid
 * @return
 */
public String queryPrecout(String cureid){ 
	String sql = "select to_char(count(*)) as countall from WDSS_PREINFO where cureid=?";
	List datalist = this.getDbo().queryList(sql, new Object[]{cureid});
	Map data = (Map)datalist.get(0);
	String count = (String)data.get("countall");
	if("0".equals(count))
		return cureid;
	return "";
}
/**
 * 添加治法信息
 * @param paradisname
 * @param memo
 * @param disid
 * @return
 */
public String addCure(String curename,String memo,String disid,String symid){
	String cureid = this.getSeqValue("SEQ_WDSS_CUREMETHOD_ID");
	String sql = "insert into WDSS_CUREMETHOD(id,CURENAME,MEMO,DISID,SYMID) VALUES(?,?,?,?,?)";
	this.getDbo().update(sql, new Object[]{cureid,curename,memo,disid,symid});
	List datalist = this.getDbo().queryList("select TO_CHAR(ID) AS ID,STANDARDNAME||'('||SYNONYMS||')' AS VALUE from WDSS_STANDARD where CATEGORY='治法'  and id=?", new Object[]{curename});
	String namestr = "";
	if(datalist.size() >0){
		Map m = (Map)datalist.get(0);
		namestr = (String)m.get("VALUE");
	}
	return cureid + "$" + namestr;
}
/**
 * 删除治法信息
 * @param disid
 * @return
 */
public String delCure(String cureid){
	String returnstr = "";
	
	String sql = "delete from  WDSS_CUREMETHOD where id=?";
	returnstr = this.getDbo().update(sql, new Object[]{cureid})+"";
	return cureid;
}
/**
 * 添加证候信息
 * @param paradisname
 * @param memo
 * @param disid
 * @return
 */
public String addSym(String symname,String memo,String disid,String ptomid){
	String symid = this.getSeqValue("SEQ_WDSS_SYMINFO_ID");
	String sql = "insert into WDSS_SYMINFO(id,SYMNAME,MEMO,DISID) VALUES(?,?,?,?)";
	this.getDbo().update(sql, new Object[]{symid,symname,memo,disid});
	String[] ptomList = ptomid.split(",");
	for(int i=0; i<ptomList.length; i++){
		String ptomvalue = ptomList[i];
		String ptosymid = this.getSeqValue("SEQ_WDSS_PTO_SYM_ID");
		sql = "insert into WDSS_PTO_SYM(id,ptoid,symid,disid) values(?,?,?,?)";
		this.getDbo().update(sql, new Object[]{ptosymid,ptomvalue,symid,disid});
	}
	List datalist = this.getDbo().queryList("select TO_CHAR(ID) AS ID,STANDARDNAME||'('||SYNONYMS||')' AS VALUE from WDSS_STANDARD where CATEGORY='证候'  and id=?", new Object[]{symname});
	String namestr = "";
	if(datalist.size() >0){
		Map m = (Map)datalist.get(0);
		namestr = (String)m.get("VALUE");
	}
	return symid + "$" + namestr;
}
/**
 * 添加方剂信息
 * @param paradisname
 * @param memo
 * @param disid
 * @return
 */
public String addPre(String prename,String memo,String disid,String curemid){
	String preid = this.getSeqValue("SEQ_WDSS_PREINFO_ID");
	String sql = "insert into WDSS_PREINFO(id,PRENAME,MEMO,DISID,CUREID) VALUES(?,?,?,?,?)";
	this.getDbo().update(sql, new Object[]{preid,prename,memo,disid,curemid});
	return preid + "$" + prename;
}
/**
 * 查询方剂所有中药信息
 * @param disid
 * @return
 */
public String queryHerbcout(String preid){ 
	String sql = "select to_char(count(*)) as countall from WDSS_HERBINFO where preid=?";
	List datalist = this.getDbo().queryList(sql, new Object[]{preid});
	Map data = (Map)datalist.get(0);
	String count = (String)data.get("countall");
	if("0".equals(count))
		return preid;
	return "";
}
/**
 * 删除方剂信息
 * @param pointid
 * @return
 */
public String delPre(String preid){
	String returnstr = "";
	String sql = "delete from  WDSS_PREINFO where id=?";
	this.getDbo().update(sql, new Object[]{preid});
	
	return preid;
}
/**
 * 添加中药信息
 * @param herbname
 * @param jiliang
 * @param jiliangdanwei
 * @param preid
 * @return
 */
public String addHerb(String herbname,String jiliang,String unittype,String method,String funcinfo,String memo,String preid,String wdssid){
 	String herbid = this.getSeqValue("SEQ_WDSS_HERBINFO_ID");

	String sql = "insert into WDSS_HERBINFO(id,HERBNAME,FUNCINFO,MEMO,JILIANG,UNITTYPE,METHOD,PREID,DISID) VALUES(?,?,?,?,?,?,?,?,?)";
	this.getDbo().update(sql, new Object[]{herbid,herbname,funcinfo,memo,jiliang,unittype,method,preid,wdssid}); 
	String unitstr = DictCacheUtil.getInst().getCodeNameByCode(unittype, "11");

	StringBuffer returnstr = new StringBuffer("[{");
	returnstr.append("id:'").append(herbid).append("',");
	returnstr.append("herbname:'").append(herbname).append("',");
	returnstr.append("jiliang:'").append(jiliang).append("',");
	returnstr.append("unittype:'").append(unitstr).append("',");
	returnstr.append("method:'").append(method).append("',");
	returnstr.append("funcinfo:'").append(funcinfo).append("',");
	returnstr.append("memo:'").append(memo).append("'");
	returnstr.append("}]"); 
	return herbid +"$" + returnstr;
}
/**
 * 删除中药信息
 * @param pointid
 * @return
 */
public String delHerb(String herbid){
	String returnstr = "";
	String sql = "delete from  WDSS_HERBINFO where id=?";
	returnstr = this.getDbo().update(sql, new Object[]{herbid})+"";
	
	return herbid;
}

/**
 * 方剂复制
 * @param preid
 * @return
 */
public String copyPreAndHerb(String preid,String mudisymid){
	StringBuffer returnstr = new StringBuffer("[{");
	String temp = "";
	String sql = "select * from DNMS_PRE WHERE ID = ?";
	List datalist = this.getDbo().queryList(sql, new Object[]{preid});
	if(datalist.size() > 0){
		Map data = (Map)datalist.get(0);
		String id =  data.get("ID")+"";

		String prename = (String)data.get("PRENAME");
		String laiyjdf = (String)data.get("FROMPRENAME");
		String pretype =  data.get("PRETYPE") +"";
		String beizhu = (String)data.get("BEIZHU");
		String eatemethod = (String)data.get("EATEMETHOD");
		//String symid =  data.get("SYMID")+""; 
		
		String newid = this.getSeqValue("SEQ_DNMS_PRE_ID");
		String newsql = "insert into DNMS_PRE(id,PRENAME,FROMPRENAME,PRETYPE,BEIZHU,SYMID,EATEMETHOD) VALUES(?,?,?,?,?,?,?)";
		this.getDbo().update(newsql, new Object[]{newid,prename,laiyjdf,pretype,beizhu,mudisymid,eatemethod}); 
		
		String jixingstr = DictCacheUtil.getInst().getCodeNameByCode(pretype, "9");
		
		returnstr.append("id:'").append(preid).append("',");
		returnstr.append("prename:'").append(prename).append("',");
		returnstr.append("laiyf:'").append(laiyjdf==null?"":laiyjdf).append("',"); 
		returnstr.append("jixing:'").append(jixingstr).append("',"); 
		returnstr.append("eatemethod:'").append(eatemethod).append("'"); 
		returnstr.append("}]"); 
		temp =  newid + "$" + returnstr.toString();
		
		//复制中药
		DBMgr dbo = this.getDbo();
		List herblist = dbo.queryList("SELECT HERBNAME,HERBCOUNT,COUNTUNIT FROM DNMS_HERB WHERE PREID=?", new Object[]{id});
		String sqlherb = "insert into DNMS_HERB(id,HERBNAME,HERBCOUNT,COUNTUNIT,PREID) VALUES(SEQ_DNMS_HERB_ID.NEXTVAL,?,?,?,?)";

		for(int i =0;i<herblist.size();i++){
			Map dataherb = (Map)herblist.get(i);
			String hname = (String)dataherb.get("HERBNAME");
			String count = dataherb.get("HERBCOUNT")+"";
			String unit = dataherb.get("COUNTUNIT")+""; 
            dbo.update(sqlherb, new Object[]{hname,count,unit,newid});
		} 
	} 
	return temp;
}
/**
 * 删除原文信息
 * @param pointid
 * @return
 */
public String deleteFile(String fileid){
	String sql = "delete from  WDSS_FILE where id=?";
	this.getDbo().update(sql, new Object[]{fileid});
	
	return fileid;
}
/**
 * 拷贝复制文献题录及疾病信息
 * @param wdssid
 * @return
 */
public String copydisdata(String wdssid,String discode){
	String  dsid = this.getSeqValue("SEQ_WDSS_RESOURCE_ID");
	String  disinfoid = this.getSeqValue("SEQ_WDSS_DISINFO_ID");;
	System.out.println("dsid:" + dsid);
	String sql = "insert into WDSS_RESOURCE SELECT "+dsid+", W.BOOKNAME, W.AUTHOR,  W.SUBJECTWORD, W.KEYWORD, W.ABSTRACT, W.PUBLISHUNIT, W.PUBLISHADDRESS, W.PUBLISHDATE, W.ISBNSTR, W.BANCI, W.YINCI,  W.ZISHU, W.MAGANAME, W.TITLE, W.ENTITLE, W.DSTYPE, W.YEARSTR,   W.ROLLSTR, W.PERIODSTR, W.PAGESTR FROM WDSS_USER.WDSS_RESOURCE W where id=?";
	int k = this.getDbo().update(sql, new Object[]{wdssid});
	String maxdiscode  = "select max(to_number(substr(discode,8,10))) as discode from WDSS_DISINFO where substr(discode,0,7)=substr('"+discode+"',0,7)";
	List datalist = this.getDbo().queryList(maxdiscode, null);
	if(k>0){
		if(datalist.size()>0){
			Map data = (Map)datalist.get(0);
			Long maxid = ((java.math.BigDecimal)data.get("discode")).longValue();
			maxid = maxid +1;
			String maxidstr = maxid +""; 
			int length = maxidstr.length();
			int num = 3 - length; 
			for(int i=0;i<num;i++){
				maxidstr = "0"+maxidstr;
			} 
			String newdiscode = discode.substring(0,7)+maxidstr;
			System.out.println("newdiscode:" + newdiscode);
			String insertdisinfo = "insert into WDSS_DISINFO(ID,DISCODE,DSID,STATE) VALUES(?,?,?,0)";
			this.getDbo().update(insertdisinfo, new Object[]{disinfoid,newdiscode,dsid});
			//拷贝附件
			String filesql = "insert into WDSS_FILE SELECT SEQ_WDSS_FILE_ID.NEXTVAL,"+disinfoid+", FILENAME, FILEPATH, UPLOADDATE, USERID FROM WDSS_FILE WHERE DISID=(select id from  wdss_disinfo where dsid="+wdssid+")";
			this.getDbo().update(filesql,null);
		}
	}
	
	return disinfoid;
}
public String deleteMr(String disid,String wdssid){
	DBMgr dbo = this.getDbo();
	String sql1 = "delete from WDSS_CUREMETHOD    where DISID=?"; 
	String sql2 = "delete from WDSS_DISCAUSEINFO  where DISID=?";
	String sql3 = "delete from WDSS_DISINFO       where id=?";
	String sql4 = "delete from WDSS_FILE          where DISID=?";
	String sql5 = "delete from WDSS_HERBINFO      where DISID=?";
	String sql6 = "delete from WDSS_PARAINFO      where DISID=?";
	String sql7 = "delete from WDSS_PREINFO       where DISID=?";
	String sql8 = "delete from WDSS_PTO_SYM       where DISID=?";
	String sql9 = "delete from WDSS_PTOMINFO      where DISID=?";
	String sql10 = "delete from WDSS_RESOURCE      where id=?"; 
	String sql11 = "delete from WDSS_SYMINFO       where DISID=?";
	String sql12 = "delete from WDSS_USERINFO      where DISID=?";
	dbo.update(sql1, new Object[]{disid});
	dbo.update(sql2, new Object[]{disid});
	dbo.update(sql3, new Object[]{disid});
	dbo.update(sql4, new Object[]{disid});
	dbo.update(sql5, new Object[]{disid});
	dbo.update(sql6, new Object[]{disid});
	dbo.update(sql7, new Object[]{disid});
	dbo.update(sql8, new Object[]{disid});
	dbo.update(sql9, new Object[]{disid});
	dbo.update(sql10, new Object[]{wdssid});
	dbo.update(sql11, new Object[]{disid});
	dbo.update(sql12, new Object[]{disid}); 
	
	return "";
}
}
